/*
 * Copyright (c) 2015. For Intelligent Group.
 */

package com.intelligent.ispc.core.service.impl;

import com.google.common.collect.Lists;
import com.intelligent.ispc.common.mapper.BeanMapper;
import com.intelligent.ispc.common.mapper.BeanUtil;
import com.intelligent.ispc.common.utils.StringUtils;
import com.intelligent.ispc.core.dto.DataDictionaryDto;
import com.intelligent.ispc.core.entity.DataDictionary;
import com.intelligent.ispc.core.repository.jpa.DataDictionaryDao;
import com.intelligent.ispc.core.service.AlarmService;
import com.intelligent.ispc.core.service.DataDictionaryService;
import com.intelligent.ispc.utils.DDCategory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import javax.persistence.criteria.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by cherry on 2015/12/10.
 */
@Service
public class AlarmServiceImpl implements AlarmService {

    @Autowired
    private DataDictionaryDao dataDictionaryDao;

    @Autowired
    private DataDictionaryService dataDictionaryService;

    @Override
    public void updateSystemAlarmRuleCCWR(DataDictionaryDto dataDictionaryDto) throws Exception {

        String parentId = dataDictionaryDto.getId().toString();
        String attributeName = dataDictionaryDto.getAttributeName();

        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("attributeName",attributeName);
        dataDictionaryDto.setId(null);
        List<DataDictionary> dataDictionaryList = dataDictionaryService.findByCategoryAndParent(DDCategory.CCWR, paramMap, parentId);
        DataDictionary dataDictionary = dataDictionaryList.get(0);
        dataDictionary = (DataDictionary)BeanUtil.CopyBeanToBean(dataDictionaryDto, dataDictionary);
        dataDictionaryDao.save(dataDictionary);
    }

    @Override
    public void updateSystemAlarmRuleCPWR(DataDictionaryDto dataDictionaryDto) throws Exception {

        String parentId = dataDictionaryDto.getId().toString();
        String attributeName = dataDictionaryDto.getAttributeName();
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("attributeName",attributeName);
        dataDictionaryDto.setId(null);

        List<DataDictionary> dataDictionaryList = dataDictionaryService.findByCategoryAndParent(DDCategory.CPWR, paramMap, parentId);
        DataDictionary dataDictionary = dataDictionaryList.get(0);
        dataDictionary = (DataDictionary)BeanUtil.CopyBeanToBean(dataDictionaryDto, dataDictionary);

        dataDictionaryDao.save(dataDictionary);
    }

}
